//
//  SearchResultCell.m
//  MeiXiu
//
//  Created by Yuan on 13-1-14.
//
//

#import "MSSearchResultCell.h"

@implementation MSSearchResultCell
@synthesize iconButton;
@synthesize addressbl; //地址
@synthesize storeNameLbl;//店名
@synthesize addButton; //
@synthesize aliasLbl;

-(void)dealloc
{
    addressbl = nil;
    storeNameLbl = nil;
    aliasLbl = nil;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        UIImageView *bgimageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 82)];
        [bgimageV setImage:[UIImage imageNamed:@"search_price_cellbg"]];
        bgimageV.tag = 200;
        [self.contentView addSubview:bgimageV];
        
        iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [iconButton setFrame:CGRectMake(10,16,50,50)];
        iconButton.layer.cornerRadius = 6.0;
        [iconButton setUserInteractionEnabled:YES];
        iconButton.layer.masksToBounds = YES;
        [self.contentView addSubview:iconButton];
        
        aliasLbl = [[UILabel alloc]initWithFrame:CGRectMake(70.0f,4.0, 200.0f, 30.0f)];
        [aliasLbl setTextColor:[UIColor colorWithRed:0.24 green:0.24 blue:0.24 alpha:1.000]];
        [aliasLbl setFont:[UIFont systemFontOfSize:18.0]];
        [aliasLbl setContentMode:UIViewContentModeScaleAspectFit];
        [aliasLbl setBackgroundColor:[UIColor clearColor]];
        [aliasLbl setAdjustsFontSizeToFitWidth:YES];
        [self.contentView addSubview:aliasLbl];
        
        storeNameLbl = [[UILabel alloc]initWithFrame:CGRectMake(70.0f,31.0, 200.0f, 20.0f)];
        [storeNameLbl setTextColor:[UIColor colorWithRed:0.24 green:0.24 blue:0.24 alpha:1.000]];
        [storeNameLbl setFont:[UIFont systemFontOfSize:14.0]];
        [storeNameLbl setContentMode:UIViewContentModeScaleAspectFit];
        [storeNameLbl setBackgroundColor:[UIColor clearColor]];
        [storeNameLbl setAdjustsFontSizeToFitWidth:YES];
        [self.contentView addSubview:storeNameLbl];
        
        UIImage *iconimage = [UIImage imageNamed:@"search_price_addressicon"];
        UIImageView *addressicon = [[UIImageView alloc]initWithFrame:CGRectMake(70, 53, iconimage.size.width, iconimage.size.height)];
        [addressicon setImage:iconimage];
        [self.contentView addSubview:addressicon];
        
        addressbl = [[UILabel alloc]initWithFrame:CGRectMake(85.0f,55.0, 200.0f,20.0f)];
        [addressbl setTextColor:[UIColor grayColor]];
        [addressbl setFont:[UIFont systemFontOfSize:14.0]];
        [addressbl setContentMode:UIViewContentModeScaleAspectFit];
        [addressbl setBackgroundColor:[UIColor clearColor]];
        [addressbl setAdjustsFontSizeToFitWidth:NO];
        [self.contentView addSubview:addressbl];
      
        
        UIImage *btnbg = [UIImage imageNamed:@"followbtn.png"];
        //        [followButton setTitle:AppLocalizedString(@"关注") forState:UIControlStateNormal];
        addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [addButton setFrame:CGRectMake(260,28,btnbg.size.width/2.0,btnbg.size.height/2.0)];
        [addButton setImage:btnbg forState:UIControlStateNormal];
        [addButton setUserInteractionEnabled:YES];
        addButton.layer.masksToBounds = YES;
        [self.contentView addSubview:addButton];

    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    [self setLabelSelect:selected];

}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated              // animate between regular and highlighted state
{
    [super setHighlighted:highlighted animated:animated];
    [self setLabelSelect:highlighted];    
}


-(void)setLabelSelect:(BOOL)selected
{
    UIView *v = [self.contentView viewWithTag:200];
    v.hidden = selected;
    if (selected) {
        aliasLbl.textColor = [UIColor whiteColor];
        addressbl.textColor = [UIColor whiteColor];
        storeNameLbl.textColor = [UIColor whiteColor];
    }
    else
    {
        aliasLbl.textColor = [UIColor blackColor];
        addressbl.textColor = [UIColor grayColor];
        storeNameLbl.textColor = [UIColor blackColor];
    }
}

@end
